package com.tim.app.ui.adapter.found;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.application.library.base.LSAdapter;
import com.application.library.widget.RatioImageView;
import com.tim.app.R;
import com.tim.app.server.entry.MusicAlbum;
import com.tim.app.util.BitmapLoader;


/**
 * 热门音乐专辑的适配器
 */
public class HotMusciAlbumAdapter extends LSAdapter {

    static final String TAG = "HotMusciAlbumAdapter";

    private Context mContext;

    public HotMusciAlbumAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_hot_music_album, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final MusicAlbum data = (MusicAlbum) getItem(position);
        if (!TextUtils.isEmpty(data.getImage())) {
            BitmapLoader.ins().loadImage(data.getImage(), holder.rivImage);
        } else {
            BitmapLoader.ins().loadImage("", holder.rivImage);
        }
        if (!TextUtils.isEmpty(data.getName())) {
            holder.tvName.setText(data.getName());
        } else {
            holder.tvName.setText("");
        }

        return convertView;
    }

    static class ViewHolder {
        RatioImageView rivImage;
        TextView tvName;

        public ViewHolder(View itemView) {
            rivImage = (RatioImageView) itemView.findViewById(R.id.rivImage);
            tvName = (TextView) itemView.findViewById(R.id.tvName);
        }
    }


}
